package com.rocketmq.base.trace;

import com.rocketmq.base.example.Const;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.common.RemotingHelper;

/**
 * @Auther: tianchao
 * @Date: 2021/9/4 21:26
 * @Description:
 */
public class TraceProducer {
    public static void main(String[] args) throws Exception {
        DefaultMQProducer producer = new
                DefaultMQProducer("traceProducer-group-name",true);
        producer.setNamesrvAddr(Const.nameServer);
        producer.start();
        for (int i = 0; i < 2; i++) {

            Thread.sleep(1000);
            //Create a message instance, specifying topic, tag and message body.
            Message msg = new Message("TrackTopicTest1" /* Topic */,
                    "TagA"+1 /* Tag */,
                    "testKey"+i,
                    ("Hello RocketMQ " +
                            i).getBytes(RemotingHelper.DEFAULT_CHARSET) /* Message body */
            );
            //Call send message to deliver message to one of brokers.
            SendResult sendResult = producer.send(msg);
            System.out.printf("%s%n", sendResult);
        }
        //Shut down once the producer instance is not longer in use.
        producer.shutdown();
    }
}
